$.extend($.fn.combobox.defaults.rules, {
	sex:{
		validator: function (value) {
			return value=="男"||value=="女";
		},
		message:'性别输入不正确!'
	}
});
$.extend($.fn.validatebox.defaults.rules, {
	mobile: {//验证手机号码
		validator: function (value) {
			var reg = /^1[3|4|5|8|9]\d{9}$/;
			return reg.test(value);
		},
		message: '输入手机号码格式不准确.'
	},
	
	idcard: {// 验证身份证
		validator: function (value) {
			return /^\d{15}(\d{2}[A-Za-z0-9])?$/i.test(value);
		},
		message: '身份证号码格式不正确'
	},
});
$.extend($.fn.datebox.defaults.rules, {   
    validDate: {    
		validator: function(value){    
            var date = $.fn.datebox.defaults.parser(value);  
            var s = $.fn.datebox.defaults.formatter(date);  
            return s==value;   
        },    
    message: '请输入正确日期格式.'    
	}  
});
$.extend($.fn.datagrid.methods, {
	editCell : function(jq, param) {
		return jq.each(function() {
			var opts = $(this).datagrid('options');
			var fields = $(this).datagrid('getColumnFields', true).concat(
				$(this).datagrid('getColumnFields'));
				for ( var i = 0; i < fields.length; i++) {
					var col = $(this).datagrid('getColumnOption', fields[i]);
					col.editor1 = col.editor;
					if (fields[i] != param.field) {
						col.editor = null;
					}
				}
			$(this).datagrid('beginEdit', param.index);
			for ( var i = 0; i < fields.length; i++) {
				var col = $(this).datagrid('getColumnOption', fields[i]);
				col.editor = col.editor1;
				}
			});
	}
});
function getRowIndex(target){
	var tr = $(target).closest('tr.datagrid-row');
	return parseInt(tr.attr('datagrid-row-index'));
}
function editrow(target){
	$('#data').datagrid('beginEdit', getRowIndex(target));
}
function saverow(target){
	$('#data').datagrid('endEdit', getRowIndex(target));
}
function cancelrow(target){
	$('#data').datagrid('cancelEdit', getRowIndex(target));
}
function myformatter(date){
	var y = date.getFullYear();
	var m = date.getMonth()+1;
	var d = date.getDate();
	return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
}
function myparser(s){
	if (!s) return new Date();
	var ss = (s.split('-'));
	var y = parseInt(ss[0],10);
	var m = parseInt(ss[1],10);
	var d = parseInt(ss[2],10);
	if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
		return new Date(y,m-1,d);
	} else {
		return new Date();
	}
}